243. GCP 全域負載平衡器進階路由設定

WHY

新的服務,就順便改一下新的負載平衡器去掛載bucket吧。
然後滿滿的坑,GCP的說明範例不知道在寫啥。

Solution

243-fig.1.png
以前都是選擇傳統版,
設定也頗簡單。

243-fig.2.png

不要看他新版上面寫建議,
就真的用,至少先弄個傳統的把你要的東西設定好。

243-fig.3.png
243-fig.4.png
上面的設定是將 domain/files/123.jpg,轉到 bucket底下的123.jpg

這邊提供一個最快的解法。

假設已經在傳統的負載平衡器上面已經建立好了規則,名稱為 abc-qa。
使用指令查詢

gcloud compute url-maps describe abc-qa

pathMatchers底下的東西抄出來,改一下,

243-fig.6.png

貼到『進階型主機與路徑規則』上面就好了(不要太相信程式碼指南)。
真的要參考,請看底下連結。

243-fig.5.png

service的部分,利用指令查詢你的服務或bucket。

gcloud compute backend-buckets list --uri
or
gcloud compute backend-services list --uri

這指令會得到類似下面的網址。

https://www.googleapis.com/compute/v1/projects/<project_name>/global/backendBuckets/<bucket_name>

service 可以為 projects/<project_name>/global/backendBuckets/<bucket_name>
或是
global/backendBuckets/<bucket_name>

Troubleshooting

  1. 出現錯誤 Operation type [update] failed with message "Invalid resource: URL_MAP/513614964978.game-result-video-qa"

錯誤的設定

defaultService: global/backendBuckets/abc-qa
name: matcher1
routeRules:
  - matchRules:
      - prefixMatch: /videos
    priority: 100
    routeAction:
      weightedBackendServices:
        - backendService: global/backendBuckets/abc-qa
          weight: 100

問顧問,說不要用 weightedBackendServices 直接指定service。

defaultService: global/backendBuckets/abc-qa
name: matcher1
routeRules:
  - matchRules:
      - prefixMatch: /videos
    priority: 100
    service: global/backendBuckets/abc-qa

ref. GCP - HTTP(S) Load Balancer L7 Backend Bucket Issue

  1. 程式碼指南的 $[DEFAULT_SERVICE_URL]是什麼

使用指令查詢

gcloud compute backend-buckets list --uri
or
gcloud compute backend-services list --uri

ref. What does "$[DEFAULT_SERVICE_URL]" refer to when setting Google Load Balancer towards a GCP Storage Bucket?

Conclusion

沒事不要用新版的應用程式負載平衡器。
官方文件要看的話,請看下面兩個連結。

  1. Advanced host, path, and route rule
  2. URL maps overview